<template>
  <div class="app-container">
    <!-- 查询和其他操作 -->
    <div class="filter-container" style="display: flex;">
      <el-input v-model="listQuery.companyName" size="mini" clearable class="filter-item" style="width: 200px;"
        placeholder="企业名称" />
      <el-input v-model="listQuery.companyCode" size="mini" clearable class="filter-item" style="width: 200px;"
        placeholder="企业信用代码" />
      <el-input v-model="listQuery.companyAddress" size="mini" clearable class="filter-item" style="width: 200px;"
        placeholder="企业地址" />
      <el-input v-model="listQuery.adminPhone" size="mini" clearable class="filter-item" style="width: 200px;"
        placeholder="管理电话" />
      <el-input v-model="listQuery.counselorPhone" size="mini" clearable class="filter-item" style="width: 200px;"
        placeholder="业务员电话" />
      <div style="width: 500px;">
        <defCity @cityData="cityDataFun" size="mini" />
      </div>
      <el-button class="filter-item" type="primary" size="mini" icon="el-icon-search" @click="handleFilter">查找
      </el-button>
      <el-button class="filter-item" type="primary" size="mini" icon="el-icon-edit" @click="handleCreate">添加</el-button>
      <el-button :loading="downloadLoading" class="filter-item" size="mini" type="primary" icon="el-icon-download"
        @click="handleDownload">导出</el-button>
    </div>

    <!-- 查询结果 -->
    <el-table v-loading="listLoading" :data="list" size="mini" border element-loading-text="正在查询中。。。" highlight-current-row>
      <!--<el-table-column align="center" label="ID" prop="id"/>-->
      <el-table-column align="center" label="企业ID" prop="id" width="80" />
      <el-table-column align="center" label="企业名称" prop="companyName" width="140px" />
      <el-table-column align="center" label="信用代码" prop="companyCode" width="250px" />
      <!--<el-table-column align="center" label="所属行业" prop="categoryInfo"/>-->

      <!--<el-table-column align="center" label="匹配课程" prop="courseName"/>-->
      <el-table-column align="center" label="已缴费人数" prop="payPeopleNum" width="100px" />
      <el-table-column align="center" label="未缴费人数" prop="unpayPeopleNum" width="100px" />
      <el-table-column align="center" label="公司地址" prop="companyAddress" width="180px">
        <template slot-scope="scope">
          <span
            v-if="scope.row.provinceName">{{ scope.row.provinceName+'/'+scope.row.cityName+'/'+scope.row.areaName }}</span>
          <span v-else>暂无</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="详细地址" prop="companyAddress" width="180px">
        <template slot-scope="scope">
          <span>{{ scope.row.companyAddress }}</span>
        </template>
      </el-table-column>

      <!--<el-table-column align="center" label="联系人/电话" prop="companyInfo"/>-->
      <el-table-column align="center" label="管理人/电话" prop="companyInfo" width="180px">
        <template slot-scope="scope">
          <span>{{ scope.row.companyInfo }}</span>
        </template>
      </el-table-column>

      <!--<el-table-column align="center" label="业务员名/电话" prop="counselorInfo"/>-->
      <el-table-column align="center" label="业务员名/电话" prop="counselorInfo" width="180px">
        <template slot-scope="scope">
          <span>{{ scope.row.counselorInfo }}</span>
        </template>
      </el-table-column>


      <el-table-column fixed="right" align="center" label="操作" width="340" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button style="width:30%;margin: 0;margin-bottom: 10px;" type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
          <el-button style="width:30%;margin: 0;margin-bottom: 10px;" type="success" size="mini" @click="handleUpdateChangePwd(scope.row)">修改密码
          </el-button>
          <el-button style="width:30%;margin: 0;margin-bottom: 10px;" type="info" size="mini" @click="queryCompany(scope.row)">详情</el-button>
          <el-button style="width:30%;margin: 0;margin-bottom: 10px;" type="info" size="mini" @click="getCourseRecord(scope.row)">培训记录</el-button>
          <el-button style="width:30%;margin: 0;margin-bottom: 10px;" type="primary" size="mini" @click="optionHandler('create', scope.row)">添加学员</el-button>
          <el-button style="width:30%;margin: 0;margin-bottom: 10px;" type="success" size="mini" @click="optionHandler('look', scope.row)">查看学员</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit"
      @pagination="getList" />

    <!-- 添加或修改对话框 -->
    <el-dialog :title="textMap[dialogStatus]" width="1000px" :visible.sync="dialogFormVisible"
      :close-on-click-modal="true">
      <el-form ref="dataForm" :rules="rules" :model="dataForm" status-icon label-position="left" label-width="100px"
        style="margin-left:50px;">
        <div style="display: flex">
          <div style="flex: 1">
            <el-form-item label="企业名称">
              <el-input v-model="dataForm.companyName" />
            </el-form-item>
            <!-- <el-form-item label="业务员姓名">
              <el-input v-model="dataForm.counselorName" />
            </el-form-item>
            <el-form-item label="业务员电话">
              <el-input v-model="dataForm.counselorPhone" type="number"/>
            </el-form-item> -->
            <el-form-item label="管理人姓名">
              <el-input v-model="dataForm.adminName" />
            </el-form-item>
            <el-form-item label="管理人电话">
              <el-input v-model="dataForm.adminPhone" type="number" />
            </el-form-item>
            <el-form-item label="业务员姓名">
              <el-input v-model="dataForm.counselorName" />
            </el-form-item>
            <el-form-item label="业务员电话">
              <el-input v-model="dataForm.counselorPhone" type="number" />
            </el-form-item>
            <!-- <el-form-item label="负责人姓名">
              <el-input v-model="dataForm.principalName"/>
            </el-form-item>
            <el-form-item label="负责人电话">
              <el-input v-model="dataForm.principalPhone" type="number"/>
            </el-form-item> -->
            <!-- <el-form-item label="联系人姓名">
              <el-input v-model="dataForm.userName"/>
            </el-form-item>
            <el-form-item label="联系人电话">
              <el-input v-model="dataForm.userPhone" type="number"/>
            </el-form-item> -->
            <el-form-item label="选择行业">
              <div style="display: flex;">
                <el-select v-model="dataForm.categoryId" filterable placeholder="大类" @change="choseBigCategory">
                  <el-option v-for="item in bigCategory" :key="item.id" :label="item.categoryName" :value="item.id" />
                </el-select>
                <el-select v-model="dataForm.smallCategoryId" filterable placeholder="小类" @change="choseSmallCategory">
                  <el-option v-for="item in smallCategory" :key="item.id" :label="item.categoryName" :value="item.id" />
                </el-select>
                <el-select v-model="dataForm.jutiCategoryId" filterable placeholder="具体行业" @change="$forceUpdate()">
                  <el-option v-for="item in jutiCategory" :key="item.id" :label="item.categoryName" :value="item.id" />
                </el-select>
              </div>
            </el-form-item>
            <el-form-item label="企业地址">
              <defCity @cityData="cityData" :defData="defData" />
            </el-form-item>
          </div>
          <div style="flex: 1;margin-left: 20px">
            <el-form-item label="营业执照" v-if="dialogStatus=='create'">
              <el-input v-model="dataForm.companyCode" />
            </el-form-item>
            <el-form-item label="详细地址">
              <el-input v-model="dataForm.companyAddress" />
            </el-form-item>
            <el-form-item label="企业总人数">
              <el-input v-model="dataForm.totalPeopleNum" type="number" />
            </el-form-item>
            <el-form-item label="劳动者总人数">
              <el-input v-model="dataForm.totalJobPeopleNum" />
            </el-form-item>
          </div>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="dialogFormVisible = false">取消</el-button>
        <el-button size="mini" v-if="dialogStatus=='create'" type="primary" @click="createData">确定</el-button>
        <el-button size="mini" v-else type="primary" @click="updateData">确定</el-button>
      </div>
    </el-dialog>

    <!-- 密码管理 -->
    <el-dialog :close-on-click-modal="false" :visible.sync="dialogFormVisibleChangePwd" status-icon title="密码设置">
      <el-form ref="dataFormChangePwd" :model="dataFormChangePwd" :rules="rulesChangePwd" status-icon
        label-position="left" label-width="100px" style="width: 80%; margin-left:50px;">
        <!--<el-form-item label="原密码" prop="oldPwd">-->
        <!--<el-input v-model="dataFormChangePwd.oldPwd" type="password" placeholder="输入原密码"/>-->
        <!--<el-input :type="passwordType" v-model="dataFormChangePwd.oldPwd" name="password" auto-complete="on" placeholder="再次确认新密码" />-->
        <!--<span class="show-pwd" @click="showPwd">-->
        <!--<svg-icon icon-class="eye" />-->
        <!--</span>-->
        <!--</el-form-item>-->
        <el-form-item label="新密码" prop="newPwd">
          <!--<el-input v-model="dataFormChangePwd.newPwd" type="password" auto-complete="off" placeholder="输入新密码"/>-->
          <el-input :type="passwordType" v-model="dataFormChangePwd.newPwd" name="password" auto-complete="on"
            placeholder="再次确认新密码" />
          <span class="show-pwd" @click="showPwd">
            <svg-icon icon-class="eye" />
          </span>
        </el-form-item>
        <el-form-item label="确认密码" prop="newPwd2">
          <!--<el-input v-model="dataFormChangePwd.newPwd2" type="password" auto-complete="off" placeholder="再次确认新密码"/>-->
          <el-input :type="passwordType" v-model="dataFormChangePwd.newPwd2" name="password" auto-complete="on"
            placeholder="再次确认新密码" />
          <span class="show-pwd" @click="showPwd">
            <svg-icon icon-class="eye" />
          </span>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="cancel">取消</el-button>
        <el-button size="mini" type="primary" @click="updateDataChangePwd">确定</el-button>
      </div>
    </el-dialog>

    <!-- 活动商品查询结果 -->
    <el-dialog :visible.sync="dialogFormVisibleCourseRecord" title="培训记录" width="90%">
      <!--<div  v-if="companyInfoData!=undefined">-->
      <!--<div class="title">培训人数:<span>{{ companyInfoData.trainNumber }}</span></div>-->
      <!--<div class="title">取证人数:<span>{{ companyInfoData.certificateNumber }}</span></div>-->
      <!--<div class="title">未取证人数:<span>{{ companyInfoData.unCertificateNumber }}</span></div>-->
      <!--<div class="title">累计缴费:<span>{{(companyInfoData.totalPrice).toFixed(2) }}</span></div>-->
      <!--</div>-->

      <el-table :data="courseRecordList" size="small" element-loading-text="正在查询中。。。" highlight-current-row>

        <!--<el-table-column align="center" label="ID" prop="id" sortable/>-->

        <el-table-column align="center" label="学生姓名" prop="studentsName" sortable />

        <el-table-column align="center" label="课程" prop="courseName" />

        <el-table-column align="center" label="学习进度" prop="status">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status===0" type="info">未开始</el-tag>
            <el-tag v-if="scope.row.status===1" type="success">进行中</el-tag>
            <el-tag v-if="scope.row.status===2" type="primary">已学完</el-tag>
          </template>
        </el-table-column>

        <el-table-column align="center" label="第一次学习时间" prop="createTime" sortable />
        <el-table-column align="center" label="再次学习时间" prop="updateTime" />

      </el-table>
      <!--<pagination v-show="courseRecordTotal>0" :total="courseRecordTotal" :page.sync="queryCourseRecordParam.page" :limit.sync="queryCourseRecordParam.limit" @pagination="courseRecord" />-->

    </el-dialog>
    <addStudent ref="addStudent" @createData="createDataSubmit" />
  </div>
</template>

<style>
  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: #889aa4;
    cursor: pointer;
    user-select: none;
  }

  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }

  .avatar-uploader .el-upload:hover {
    border-color: #20a0ff;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 120px;
    height: 120px;
    line-height: 120px;
    text-align: center;
  }

  .avatar {
    width: 145px;
    height: 145px;
    display: block;
  }
</style>

<script>
  import {
    listCompany,
    createCompany,
    updateCompany,
    deleteCompany,
    changePwd,
    register,
    queryCompanyInfo,
    companycreateStudent,
    queryCourseRecord
  } from '@/api/company'
  import {
    studentlist,
    studentupdate
  } from '@/api/student.js'
  import {
    uploadPath
  } from '@/api/storage'
  import {
    getToken
  } from '@/utils/auth'
  import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
  import {
    industryCategoryAll
  } from '@/api/companyOperate'
  import defCity from '@/components/BaseCity/defCity'
  import addStudent from './componments/addStudent.vue'
  export default {
    name: 'Order',
    components: {
      Pagination,
      defCity,
      addStudent
    },
    data() {
      const validatePass = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入密码'))
        } else {
          callback()
        }
      }
      const validatePass2 = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请再次输入密码'))
        } else if (value !== this.dataFormChangePwd.newPwd) {
          callback(new Error('两次输入密码不一致!'))
        } else {
          callback()
        }
      }
      return {
        uploadPath,
        passwordType: 'password',
        updateParam: undefined,
        list: undefined,
        total: 0,
        listLoading: true,
        listQuery: {
          id: undefined,
          page: 1,
          limit: 20,
          payType: undefined,
          companyName: undefined,
          categoryName: undefined,
          companyAddress: undefined,
          sort: 'id',
          order: 'desc'
        },
        dataForm: {
          id: undefined,
          courseId: undefined,
          companyName: undefined,
          companyCode: undefined,
          companyAddress: undefined,
          categoryName: undefined,
          userName: undefined,
          userPhone: undefined,
          categoryId: undefined,
          counselorName: undefined,
          counselorPhone: undefined,
          principalName: undefined,
          principalPhone: undefined,
          adminName: undefined,
          adminPhone: undefined,
          payPeopleNum: undefined,
          unpayPeopleNum: undefined,
          totalPeopleNum: undefined,
          totalJobPeopleNum: undefined,
          deleteMark: undefined,
          createDate: undefined
        },
        dialogFormVisible: false,
        dialogStatus: '',
        textMap: {
          update: '编辑',
          create: '创建'
        },
        rules: {
          companyName: [{
            required: true,
            message: '企业名称不能为空',
            trigger: 'blur'
          }],
          companyCode: [{
            required: true,
            message: '信用代码不能为空',
            trigger: 'blur'
          }],
          userName: [{
            required: true,
            message: '企业联系人不能为空',
            trigger: 'blur'
          }],
          userPhone: [{
            required: true,
            message: '企业联系人电话不能为空',
            trigger: 'blur'
          }],
          principalName: [{
            required: true,
            message: '负责人名称不能为空',
            trigger: 'blur'
          }],
          principalPhone: [{
            required: true,
            message: '负责人电话不能为空',
            trigger: 'blur'
          }],
          adminName: [{
            required: true,
            message: '管理员名称不能为空',
            trigger: 'blur'
          }],
          adminPhone: [{
            required: true,
            message: '管理员电话不能为空',
            trigger: 'blur'
          }],
          counselorName: [{
            required: true,
            message: '业务员姓名不能为空',
            trigger: 'blur'
          }],
          counselorPhone: [{
            required: true,
            message: '业务员电话不能为空',
            trigger: 'blur'
          }],
          companyAddress: [{
            required: true,
            message: '企业地址不能为空',
            trigger: 'blur'
          }],
          totalPeopleNum: [{
            required: true,
            message: '企业总人数不能为空',
            trigger: 'blur'
          }],
          totalJobPeopleNum: [{
            required: true,
            message: '职业总人数不能为空',
            trigger: 'blur'
          }],
          logoPasswd: [{
            required: true,
            message: '登陆密码不能为空',
            trigger: 'blur'
          }],
          categoryId: [{
            required: true,
            message: '行业大类不能为空',
            trigger: 'blur'
          }]
        },
        downloadLoading: false,
        tags: [{
            name: '全部',
            cid: ''
          },
          {
            name: '微信',
            cid: 1
          },
          {
            name: '转账',
            cid: 2
          },
          {
            name: '线下',
            cid: 3
          }
        ],
        bgindex: -1,

        listChangePwd: undefined,
        dialogFormVisibleChangePwd: false,
        dataFormChangePwd: {
          companyId: undefined,
          oldPwd: undefined,
          newPwd: undefined, // 新密码
          newPwd2: undefined // 再次确认新密码
        },
        rulesChangePwd: {
          // oldPwd: [
          //   { required: true, message: '旧密码不能为空', trigger: 'blur' }
          // ],
          newPwd: [{
              required: true,
              message: '新密码不能为空',
              trigger: 'blur'
            },
            {
              validator: validatePass,
              trigger: 'blur'
            }
          ],
          newPwd2: [{
              required: true,
              message: '确认密码不能为空',
              trigger: 'blur'
            },
            {
              validator: validatePass2,
              trigger: 'blur'
            }
          ]
        },
        queryCourseRecordParam: {
          page: 1,
          limit: 20,
          companyId: undefined,
          sort: 'add_time',
          order: 'desc'
        },
        queryCompanyParam: {
          companyId: undefined
        },
        courseRecordList: undefined,
        companyInfoData: undefined,
        dialogFormVisibleCourseRecord: false,
        courseRecordTotal: 0,
        bigCategory: undefined,
        smallCategory: undefined,
        jtCategory: undefined,
        jutiCategory: undefined,
        industryCategoryList: undefined,
        industryCategoryParam: {
          pid: 0
        },
        industryCategoryAllList: undefined,
        industryCategoryAll: undefined,
        defData: []
      }
    },
    computed: {
      headers() {
        return {
          'X-Litemall-Admin-Token': getToken()
        }
      }
    },
    created() {
      this.getList()
      // this.queryCity()
    },
    methods: {
      createDataSubmit (e) {
        companycreateStudent(e)
          .then(() => {
            this.$notify.success({
              title: '成功',
              message: '添加成功'
            })
           this.$refs.addStudent.close()
          })
          .catch(response => {
            this.$notify.error({
              title: '失败',
              message: response.data.message
            })
          })
        console.log(e)
      },
      optionHandler (type, row) {
        switch (type){
          case 'create':
            this.$refs.addStudent.open(type, row)
            break;
          case 'look':
            let routeData = this.$router.resolve({ path: '/student/studentindex', query: {  companyId: row.id } })
            window.open(routeData.href, '_blank')
            break;
          default:
            break;
        }
      },
      cityDataFun(e) {
        this.listQuery.provinceName = e.province.label
        this.listQuery.cityName = e.city.label
        this.listQuery.areaName = e.area.label
      },
      cityData(e) {
        this.dataForm.provinceName = e.province.label
        this.dataForm.cityName = e.city.label
        this.dataForm.areaName = e.area.label
      },
      handleDownload() {
        this.downloadLoading = true
        import('@/vendor/Export2Excel').then(excel => {
          const tHeader = ['企业名称', '信用代码', '已缴费人数', '未缴费人数', '公司地址', '联系人/电话', '业务员名/电话']
          const filterVal = ['companyName', 'companyCode', 'payPeopleNum', 'unpayPeopleNum', 'companyAddress',
            'companyInfo', 'counselorInfo'
          ]
          excel.export_json_to_excel2(tHeader, this.list, filterVal, '企业信息')
          this.downloadLoading = false

        })
      },
      // 标签类事件
      tagclick(cid, index) {
        if (this.bgindex === index) {
          this.bgindex = -1
          this.listQuery.payType = ''
          this.getList()
        } else {
          this.bgindex = index
          this.listQuery.payType = cid
          this.getList()
        }
      },
      getCourseRecord(row) {
        this.queryCourseRecordParam.companyId = row.id
        this.queryCompanyParam.companyId = row.id
        this.courseRecord()
        this.getCompanyInfo()
        this.dialogFormVisibleCourseRecord = true
      },
      courseRecord() {
        queryCourseRecord(this.queryCourseRecordParam)
          .then(response => {
            this.courseRecordList = response.data.data.items
            this.courseRecordTotal = response.data.data.total

          })
          .catch(() => {
            this.courseRecordList = []
            this.courseRecordTotal = 0
          })
      },
      getCompanyInfo() {
        queryCompanyInfo(this.queryCompanyParam)
          .then(response => {
            this.companyInfoData = response.data.data
          })
          .catch(() => {
            this.companyInfoData = undefined;
          })
      },
      getList() {
        this.listLoading = true
        listCompany(this.listQuery)
          .then(response => {
            this.list = response.data.data.items
            this.total = response.data.data.total
            this.listLoading = false
          })
          .catch(() => {
            this.list = []
            this.total = 0
            this.listLoading = false
          })
      },
      handleFilter() {
        this.listQuery.page = 1
        this.getList()
      },
      resetForm() {
        this.dataForm = {
          id: undefined,
          courseId: undefined,
          companyName: undefined,
          companyCode: undefined,
          companyAddress: undefined,
          categoryName: undefined,
          userName: undefined,
          userPhone: undefined,
          categoryId: undefined,
          counselorName: undefined,
          counselorPhone: undefined,
          principalName: undefined,
          principalPhone: undefined,
          adminName: undefined,
          adminPhone: undefined,
          payPeopleNum: undefined,
          unpayPeopleNum: undefined,
          totalPeopleNum: undefined,
          totalJobPeopleNum: undefined,
          deleteMark: undefined,
          createDate: undefined
        }
      },
      handleCreate() {
        this.resetForm()
        this.dialogStatus = 'create'
        this.dialogFormVisible = true
        this.defData = ['贵州省', '贵阳市', '观山湖区']
        this.dataForm.provinceName = '贵州省'
        this.dataForm.cityName = '贵阳市'
        this.dataForm.areaName = '观山湖区'
        this.queryIndustryCategoryAll()
        this.$nextTick(() => {
          this.$refs['dataForm'].clearValidate()
        })
        this.queryIndustryCategoryAll()
      },
      uploadPicUrl: function(response) {
        this.dataForm.invoiceUrl = response.data.url
      },
      createData() {
        this.$refs['dataForm'].validate(valid => {
          if (valid) {
            console.log(this.dataForm)
            this.dataForm.principalName = this.dataForm.adminName
            this.dataForm.principalPhone = this.dataForm.adminPhone
            this.dataForm.userName = this.dataForm.adminName
            this.dataForm.userPhone = this.dataForm.adminPhone
            register(this.dataForm)
              .then(response => {
                this.list.unshift(response.data.data)
                this.dialogFormVisible = false
                this.$notify.success({
                  title: '成功',
                  message: '创建成功'
                })
              })
              .catch(response => {
                this.$notify.error({
                  title: '失败',
                  message: response.data.message
                })
              })
          }
        })
      },
      handleUpdate(row) {
        this.dataForm = Object.assign({}, row)
        this.dialogStatus = 'update'
        this.dialogFormVisible = true
        // this.dataForm.categoryId = row
        if (!row.provinceName) {
          this.defData = []
        } else {
          this.defData = [row.provinceName, row.cityName, row.areaName]
        }
        this.queryIndustryCategoryAll()
        this.$nextTick(() => {
          this.$refs['dataForm'].clearValidate()
        })
      },
      updateData() {
        this.$refs['dataForm'].validate(valid => {
          if (valid) {
            updateCompany(this.dataForm)
              .then(() => {
                for (const v of this.list) {
                  if (v.id === this.dataForm.id) {
                    const index = this.list.indexOf(v)
                    this.list.splice(index, 1, this.dataForm)
                    break
                  }
                }
                this.getList()
                this.dialogFormVisible = false
                this.$notify.success({
                  title: '成功',
                  message: '更新成功'
                })
              })
              .catch(response => {
                this.$notify.error({
                  title: '失败',
                  message: response.data.message
                })
              })
          }
        })
      },
      handleDelete(row) {
        deleteCompany(row)
          .then(response => {
            this.$notify.success({
              title: '成功',
              message: '删除成功'
            })
            const index = this.list.indexOf(row)
            this.list.splice(index, 1)
          })
          .catch(response => {
            this.$notify.error({
              title: '失败',
              message: response.data.message
            })
          })
      },

      cancel() {
        this.dataFormChangePwd = {
          oldPwd: '',
          newPwd: '',
          newPwd2: ''
        }
        this.$nextTick(() => {
          this.$refs['dataFormChangePwd'].clearValidate()
        })
      },
      handleUpdateChangePwd(row) {
        this.dataFormChangePwd.companyId = row.id
        // this.dataFormChangePwd.newPwd = undefined
        // this.dataFormChangePwd.new2Pwd = undefined
        this.dialogFormVisibleChangePwd = true
        this.$nextTick(() => {
          this.$refs['dataFormChangePwd'].clearValidate()
        })
      },
      updateDataChangePwd() {
        this.$refs['dataFormChangePwd'].validate(valid => {
          if (valid) {
            changePwd(this.dataFormChangePwd)
              .then(() => {
                this.dialogFormVisibleChangePwd = false
                this.$notify.success({
                  title: '成功',
                  message: '更新成功'
                })
              })
              .catch(response => {
                this.$notify.error({
                  title: '失败',
                  message: response.data.message
                })
              })
          }
        })
      },
      showPwd() {
        if (this.passwordType === 'password') {
          this.passwordType = ''
        } else {
          this.passwordType = 'password'
        }
      },

      queryCompany(row) {
        this.$router.push({
          path: '/companyManage/query',
          query: {
            companyId: row.id
          }
        })
        console.log(row.id)
      },
      queryIndustryCategoryAll() {
        industryCategoryAll()
          .then(response => {
            this.industryCategoryAllList = this.bigCategory = response.data.data
            // 接收数据并缓存
            for (var i in this.bigCategory) {
              console.log(this.dataForm.categoryId)
              if (this.dataForm.categoryId === this.bigCategory[i].id) {
                this.smallCategory = this.bigCategory[i].adminIndustryCategoryVos
                for (var j in this.smallCategory) {
                  if (this.dataForm.smallCategoryId === this.smallCategory[j].id) {
                    this.jutiCategory = this.smallCategory[j].adminIndustryCategoryVos
                  }
                }
              }
            }
          })
          .catch(() => {
            this.industryCategoryAllList = undefined
          })
      },
      // 选择大分类
      choseBigCategory: function(e) {
        this.smallCategory = undefined // 重置数据
        this.dataForm.smallCategoryId = undefined // 重置选项
        this.jutiCategory = undefined // 重置数据
        this.dataForm.jutiCategoryId = null // 重置选项
        this.courseAllListOne = undefined // 重置课程
        this.dataForm.courseId = undefined // 重置课程
        for (var i in this.bigCategory) {
          if (e === this.bigCategory[i].id) {
            this.smallCategory = this.bigCategory[i].adminIndustryCategoryVos
            this.dataForm.smallCategoryId = this.smallCategory[0].id // 默认第一项
            this.jutiCategory = this.smallCategory[0].adminIndustryCategoryVos
            this.dataForm.jutiCategoryId = this.jutiCategory[0].id // 默认第一项
            // 筛选出符合条件的课程
            // for (var j in this.courseAllList) {
            //   if (e === this.courseAllList[j].categoryId) {
            //     this.courseAllListOne = this.courseAllList[j].adminCourseVos
            //   }
            // }
          }
        }
        console.log(this.jutiCategory)
      },
      // 选择小分类
      choseSmallCategory: function(e) {
        this.jutiCategory = undefined
        this.dataForm.jutiCategoryId = undefined // 重置选项
        this.courseAllListOne = undefined // 重置课程
        this.dataForm.courseId = undefined // 重置课程
        for (var i in this.smallCategory) {
          if (e === this.smallCategory[i].id) {
            this.jutiCategory = this.smallCategory[i].adminIndustryCategoryVos
            this.dataForm.jutiCategoryId = this.jutiCategory[0].id // 默认第一项
            // 筛选出符合条件的课程
            // for (var j in this.courseAllList) {
            //   if (e === this.courseAllList[j].categoryId) {
            //     this.courseAllListOne = this.courseAllList[j].adminCourseVos
            //   }
            // }
          }
          // console.log("  this.jutiCategory========="+  this.jutiCategory)
          // console.log("   this.dataForm.jutiCategoryId+++++++++++++++"+   this.dataForm.jutiCategoryId)
        }
        console.log(this.jutiCategory)
      },
      // 选择具体行业
      choseJutiCategory: function(e) {
        for (var i in this.jutiCategory) {
          if (e === this.jutiCategory[i].id) {
            this.dataForm.jutiCategoryId = this.jutiCategory[i].id
          }
        }
      },
      // completeInfoFunc() {
      //   companyCompleteInfo(this.dataForm)
      //     .then(response => {
      //       this.queryCourseParam.categoryId = response.data.data.categoryId
      //       this.queryCourse()
      //       this.dialogFormVisible = true
      //     })
      //     .catch(response => {
      //       this.$notify.error({
      //         title: '失败',
      //         message: response.data.message
      //       })
      //     })
      // },

    }
  }
</script>
